package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-03-17
 * Time: 18:49
 */
//设置中断标志位
public class ThreadDemo1 {
    public static boolean isQuit=false;
    public static void main(String[] args)  {

        Thread t=new Thread(()->{
            while(!isQuit){
                System.out.println("hello t");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程结束");

        });
        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        //主线程中修改isQuit的值
        isQuit=true;
    }
}
